package com.ruoyi.web.wx.controller;

import com.ruoyi.web.wx.entity.TokenEntity;
import com.ruoyi.web.wx.utils.JwtUtil;

import java.util.*;

public class Testone {

    public static void main(String[] args) {
      TokenEntity ioas8doiasoiod = createToken("oO5zI5UkTzsjJLU0V3GohmBTsowE");
        String token = ioas8doiasoiod.getToken();
        System.out.println(token);


    }

    public static TokenEntity createToken(String userId) {
        //当前时间
        Date now = new Date();
        //过期时间
        Date expireTime = new Date(now.getTime() + 10000 * 1000);
        String sign = JwtUtil.sign(userId, false);
        TokenEntity tokenEntity = new TokenEntity();
        tokenEntity.setId(UUID.randomUUID().toString().toUpperCase());
        tokenEntity.setUserId(userId);
        tokenEntity.setToken(sign);
        tokenEntity.setUpdateTime(now);
        tokenEntity.setExpireTime(expireTime);

        return tokenEntity;
    }

    public static void test() {
        Random random = new Random();
        //总金额
        int total = 1000;//所有金额都是以分为单位的(金融界)
        //红包数量
        int num = 13;
        //最小红包
        int min = 1;
        List<Integer> list = new ArrayList<Integer>();
        int totalTmp = 0;
        for (int i = 0; i < num; i++) {
            int hongbao = 0;
            //预留红包(不然第一个红包很多，第二个也很大，后面的红包没钱了)
            Integer pre = min * (num - i - 1);
            /*除以5 是为了随便生成的数太大，而导致红包分配不均匀()
                这个数字越大，导致最后一个红包很大，其他的很小
             */
            hongbao = random.nextInt((total - pre - totalTmp) / 5);
            hongbao = hongbao < min ? min : hongbao;
            if (i == num - 1) {
                hongbao = total - totalTmp;
            }
            totalTmp += hongbao;
            System.out.println("a"+(i+2)+"="+hongbao);
            list.add(hongbao);
        }

        //校验生成的红包总金额是否一致
        int amount = 0;
        for (Integer a : list) {
            amount += a;
        }
        System.out.println("生成个数" + list.size());
        System.out.println("总和" +amount);

    }


}
